var amcp = {
	maxID: 0,
	create: function (blockName) {
		var blockID = this.makeNewID();
		var block = $("#am-cp-" + blockName).clone().attr("id", "am-block-" + blockID);
		$("#am-cp-okcancel").clone().removeAttr("id").appendTo(block.find(".panel-body").first());
		block.find("[data-update-attr]").each(function () {
			var elem = $(this);
			var updateAttr = elem.attr("data-update-attr");
			elem.attr(updateAttr, "am-block-" + blockID + "-" + elem.attr("data-update-tag"));
		});
		return block;
	},
	makeNewID: function () {
		return ++this.maxID;
	},
	getBlockID: function (elementID) {
		return parseInt(elementID.replace("am-block-", ""));
	}
};

$(function () {
	amcp.create("command").appendTo($("#am-pastebin"));
});
